package com.atguigu1.core.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 * @description: 行动算子案例
 * @time: 2021-03-12 11:45
 * @author: baojinlong
 **/
object Spark04CountByValueAndCountByKey {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("rdd")
    // 设置rdd分区数字
    val sparkContext = new SparkContext(conf)
    val rdd: RDD[Int] = sparkContext.makeRDD(Seq(1, 2, 3, 4), numSlices = 2)
    println(rdd.countByValue())
    val rddValue2: RDD[(String, Int)] = sparkContext.makeRDD(Seq(("a", 2), ("b", 33), ("a", 4)))
    println(rddValue2.countByKey())
    sparkContext.stop()
  }
}
